-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat): support for historical expressions #185
Conversation
@arodidev Are you planning on setting up the HD object in the expression runner's context to make it possible to resolve expressions like: Something like: class HistoricalDataSourceService {
dataSourceMap: Record<string, any> = {};
putObject(key: string, value: any) {
this.dataSourceMap[key] = value;
}
getObject(key: string) {
return this.dataSourceMap[key];
}
}
// Instantiate one
export const HD = new HistoricalDataSourceService();
// Setup previous encounter
HD.putObject('prevEnc', {
value: encounterContex.previousEncounter,
getValue(concept) {
// lookup obs
return this.value.obs.find((obs) => obs.concept.uuid == concept)?.value;
},
});
// We then add the instance of `HistoricalDataSourceService ` to the context of the expression runner. |
Not really, I believe we already support functionality for retrieving the field's previous value by concept UUID from the previous encounter, my implementation is just a reuse of the existing logic but with minor tweaks. Was the idea to implement the functionality you've mentioned above? |
@arodidev Well to the most part that may work, except for a few edge cases. If you checkout this Ampath form. It seems to paint a more complicated scenario: {
"label": "Line of ART patient is taking:",
"id": "current_arv_line",
"historicalExpression": "!_.isEmpty(HD.getObject('prevEnc').getValue('a89b6a62-1350-11df-a1f1-0026b9348838')) ? undefined : HD.getObject('prevEnc').getValue('04616f5d-b961-4f41-bbd7-bcc0dd235577')",
"questionOptions": {
"concept": "04616f5d-b961-4f41-bbd7-bcc0dd235577",
"answers": [
{
"concept": "034047bd-3fa1-4b2a-b0f0-2787e9b9f7b3",
"label": "First line regimen"
},
{
"concept": "8f8a715d-e49a-4b2c-aa3a-83fa9d7a4254",
"label": "Second line regimen"
},
{
"concept": "a90ebdd2-351f-485a-b850-4938fcca2729",
"label": "Third line regimen"
}
],
"rendering": "select"
},
"type": "obs",
"validators": [
{
"type": "js_expression",
"failsWhenExpression": "isEmpty(myValue) && !isEmpty(onArt) && onArt === 'a899b35c-1350-11df-a1f1-0026b9348838'",
"message": "Patient previously marked as on ART. Please provide the treatment category."
}
],
"hide": {
"hideWhenExpression": "onArt !== 'a899b35c-1350-11df-a1f1-0026b9348838'|| arrayContains (['6bf34991-7414-4b5e-ad75-ca217d4c4939'],visitTypeUuid)"
}
}
Would the existing logic meet the semantics of the "historicalExpression" above? |
@samuelmale I see, back to the drawing board it is... |
…openmrs-form-engine-lib into historical-expressions
* (BREAKING) Rename files and reorganize styles rebase cleanups reference refactors * more refactors * more clean ups * forms folder changes and aligns styles * rebase fixes * more clean ups * corrects rebase residue
* Implement i18next for @openmrs/esm-form-engine-lib * Load translation resources in i18next on loading * Loading translation resources when language is changed * Translate form labels with fetched form translation resources * Review changes * Updated withFormEngineTranslations * Fixed failing tests * Cleanup
…expression (openmrs#196) * feat: disbale multiCheckbox input options given provided expression * chore: add unit tests * bg: fix failed tests * fix: fix value refrencing fields * refactor: fix linting * refactor: fix linting * chore: add test case * chore: rebase branch to main * chore: fix tests * refactor: fix lint
…openmrs-form-engine-lib into historical-expressions
Requirements
Summary
This PR introduces support for historical expressions to the form's engine by leveraging the existing
previous-value
functionality, making the previous value available when eitherformField.historicalExpression
orformField.questionOptions.enablePreviousValue
resolve totrue
.This is enabled by refactoring the
questionOptions
propertyusePreviousValueDisabled
toenablePreviousValue
to allow for lexical accuracy when using their resolved boolean values to enable and disable theprevious-value
functionality.By default, the previous encounter will always be available in the form unless explicitly specified otherwise. ie
formOptions.usePreviousValueDisabled == true
and using this would make the historical expression functionality seize to work.Screenshots
Related Issue
Other